import Vue from 'vue'
import VueRouter from 'vue-router'
import Home from '../views/linjia/index.vue'
import myfooter from '../components/myfooter'
import types from '../views/types/index.vue'
import video from '../views/video/index.vue'
import my from '../views/my/index.vue'
import login from '../views/my/login.vue'
import register from  '../views/my/register.vue'
import myindex from '../views/my/myindex.vue'
import cart from '../views/cart/index.vue'
import store from '@/store/index'
import address from '@/views/address'
import repassword from '../views/my/repassword.vue'
import likedvideo from '../views/likedvideo/index.vue'

Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    component: Home
  },
  {
    path:'/myfooter',
    component:myfooter
  },
  {
    path:'/types',
    component:types
  },
  {
    path:'/video',
    component:video
  },
  {
    path:'/cart',
    component:cart
  },
  { 
  path:'/my',
  component:my,
  children:[
    {
      path:'/',
      component:myindex
    },
    
  {    
    path :'login',
    component:login
  } ,
  {
    path:'register',
    component:register
  },
  {
    path:'repassword',
    component:repassword
  }
 
]
  },
  {
    path:'/address',
    component:address
  },
  {
    path:'/likedvideo',
    component:likedvideo
  },
  



]

const router = new VueRouter({
  routes
})
router.afterEach((to,from)=>{
  var active
  if(to.path.startsWith('/my'))
  {
    active = 4
  }
  if(to.path === '/')
  {
    active = 0 
  }else if(to.path === '/types')
  {
    active = 1
  }else if(to.path === '/video')
  {
    active = 2
  }else if(to.path === '/cart')
  {
    active = 3
  }
  store.commit('changeActive',active)
})
export default router
